package com.fish.admin.module.system.manager;

import com.fish.admin.module.system.domain.entity.SysAuthority;
import com.fish.admin.module.system.domain.entity.SysMenu;
import com.fish.admin.module.system.enums.SubjectTypeEnum;
import com.fish.admin.module.system.mapper.SysMenuMapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class SysMenuManager {


    private final SysMenuMapper sysMenuMapper;
    public List<SysMenu> listByRoleId(Long roleId) {
        MPJLambdaWrapper<SysMenu> wrapper = new MPJLambdaWrapper<SysMenu>();
        wrapper.selectAll(SysMenu.class)
                .leftJoin(SysAuthority.class,on->on.eq(SysMenu::getId, SysAuthority::getAuthorityId))
                .eq(SysAuthority::getSubjectId, roleId)
                .eq(SysAuthority::getSubjectType, SubjectTypeEnum.ROLE.getValue());
        return sysMenuMapper.selectJoinList(SysMenu.class, wrapper);
    }


}
